package junit;


import com.item1024.pojo.OperateLog;
import com.item1024.service.OperateLogService;
import org.apache.log4j.Logger;
import org.junit.Test;

import javax.annotation.Resource;
import java.util.Date;

import static org.junit.Assert.assertEquals;

/**
 * @author 阳十三
 * @email wdful165177@gmail.com
 * @blog http://www.item1024.com
 * @date 2017/8/2
 */
public class WebTest extends BaseJunitTest {
    Logger logger = Logger.getRootLogger();
    /**
     * 收藏商品查询测试   顺便用junit的比较方法测试pagehelper的分页属性
     */
//    public void findHoseList() {
//        PageHelper.startPage(1, 3); // 核心分页代码
//        List<HouseList> houseLists = houseListService.findHouseListAll();
//        for (HouseList houseList : houseLists) {
//            System.out.println(houseList.getHouseId());
//        }
//        PageInfo pageInfo = new PageInfo(houseLists);
//        //测试PageInfo全部属性
//        //PageInfo包含了非常全面的分页属性
//        System.out.println(pageInfo.getPrePage());
//        System.out.println(pageInfo.getNavigateLastPage());
//        System.exit(0);
//        assertEquals(1, pageInfo.getPageNum());
//        assertEquals(3, pageInfo.getPageSize());
//        assertEquals(1, pageInfo.getStartRow());
//        assertEquals(3, pageInfo.getEndRow());
//        assertEquals(30, pageInfo.getTotal());
//        assertEquals(10, pageInfo.getPages());
//        assertEquals(1, pageInfo.getFirstPage());
//        assertEquals(8, pageInfo.getLastPage());
//        assertEquals(false, pageInfo.isHasPreviousPage());
//        assertEquals(true, pageInfo.isHasNextPage());
//    }

    /**
     * 日志记录测试
     * 返回的 影响条数 和 插入的行级id
     */
    @Resource
    private OperateLogService operateLogService;
    @Test
    public void addOperateLogTest() {
        OperateLog userOperateLog = new OperateLog();
        userOperateLog.setOperateCreatetime(new Date(System.currentTimeMillis()));
//        userOperateLog.setUser_id((int)request.getSession().getAttribute("userid"));
        userOperateLog.setUserId(123);
        userOperateLog.setOperateTodo("写入日志测试");
        userOperateLog.setOperateType("java测试");
        int colum = operateLogService.insert(userOperateLog);
        System.out.println("影响条数:" + colum);
        System.out.println("插入行:" + userOperateLog.getOperateId());
    }
}
